package com.gblfy.httpclinet.controller;

import com.gblfy.httpclinet.service.HttpClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HttpClientController {

    @Autowired
    private HttpClientService httpClientService;

    /**
     * 中台处理get请求（无参）
     * 案例:http://localhost:8080/get/noParams/zbx?token=123&batch_no=567
     *
     * @param paramRequest
     * @return
     */
    @GetMapping(value = "/get/noParams/*", produces = "application/json;charset=UTF-8")
    public String receiveHttpClientGetToHttp(HttpServletRequest paramRequest) throws Exception{
        return httpClientService.receiveHttpClientGetToHttp(paramRequest);
    }

    /**
     * 中台处理post请求json（入参）
     * 案例:http://localhost:8080/get/noParams/zbx?token=123&batch_no=567
     *
     * @param paramRequest
     * @return
     */
    @PostMapping(value = "/post/josn/Params/*", produces = "application/json;charset=UTF-8")
    public String receiveHttpClientPostJsonToHttp(HttpServletRequest paramRequest, @RequestBody String requestBody)throws Exception {
        return httpClientService.receiveHttpClientPostToHttp(paramRequest, requestBody);
    }
    @PostMapping(value = "/post/Params/*", produces = "text/html;charset=UTF-8")
    public String receiveHttpClientPostToHttp(HttpServletRequest paramRequest, @RequestBody String requestBody)throws Exception {
        return httpClientService.receiveHttpClientPostToHttp(paramRequest, requestBody);
    }
}
